/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package EmpMonthlySal;

import Employee.EmployeeBean;
import User.UserBean;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Mukesh
 */
public class ChkEmp1 extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        HttpSession session = request.getSession();
        try {
            String empId = request.getParameter("empid");
            //out.print(empId);
            if (empId.length() > 3) {
                String s = empId.substring(3);
                //out.print(s);
                int empid = Integer.parseInt(s);
                UserBean ub = User.Query.viewSpecific(empid);
                if (ub.getUserId() != 0) {
                    EmployeeBean eb = ub.getEmployeeBean();
                    Designation.DesignationBean db = eb.getDesignationBean();

                    response.sendRedirect("/RIT/Services/Payroll/AddMonthlySal.jsp?empid=" + eb.getUserId() + "&emp=" + ub.getEmployeeName() + "&desig=" + db.getDesignation());
                } else {
                    session.setAttribute("msg", "Employee Not Found.!");
                    session.setAttribute("status", "Fail");
                    response.sendRedirect("/RIT/Services/Payroll/CalcSalSearch.jsp");
                }
            } else {
                session.setAttribute("msg", "Wrong Format Employee ID! or might be not Exist!");
                session.setAttribute("status", "Fail");
                response.sendRedirect("/RIT/Services/Payroll/CalcSalSearch.jsp");
            }
        } catch (Exception e) {
            session.setAttribute("msg", "Wrong Format Employee ID! or might be not Exist!(e)");
            session.setAttribute("status", "Fail");
            response.sendRedirect("/RIT/Services/Payroll/CalcSalSearch.jsp");
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(ChkEmp1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(ChkEmp1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
